﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class myplatform : System.Web.UI.Page
{

    string s_where, s_order;
    string curindex = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["sTittle"] = "教师专区>>我的讲台";
            LB1.Attributes.Add("style", "background:url(../images/study3.gif) left top no-repeat;color:#fff;");
            DataBrid();
        }
    }


    //绑定数据
    private void DataBrid()
    {
        int record = 0;
        int count = 0;
        s_order = "ORDER BY [id] DESC";
    
        s_where = " where ([laoshi] = '" + Session["sUserName"].ToString().Trim() +
            "' OR [writer] = '" + Session["sUserName"].ToString().Trim() + "') AND (([confirm] = '新建') OR ([confirm] = '审核未通过') OR ([confirm] = '终审未通过'))";
        Session["sqlwhere"] = s_where;
        string sqlText = "[id], [name],[username1],[confirm]";
        DataTable DT = DbHelper.ExecutePage(sqlText, "[kecheng_laoshi]" + s_where, "id", s_order, Pager.CurrentPageIndex, Pager.PageSize, out record, out count, null);
        Pager.RecordCount = record;
        this.GridView1.DataSource = DT;
        this.GridView1.DataBind();
    }



    //李红新更改 2010-09-17 条件绑定数据
    private void DataBrid(string sqlwhere)
    {
        int record = 0;
        int count = 0;
        s_order = "ORDER BY [id] DESC";
        string sqlText = "[id], [name],[username1],[confirm]";
        DataTable DT = DbHelper.ExecutePage(sqlText, "[kecheng_laoshi]" + sqlwhere, "id", s_order, Pager.CurrentPageIndex, Pager.PageSize, out record, out count, null);
        Pager.RecordCount = record;
        this.GridView1.DataSource = DT;
        this.GridView1.DataBind();
    }



    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lbt = e.Row.FindControl("LinkButton1") as LinkButton;
            if (lbt != null)
            {
                lbt.OnClientClick = string.Format("openurl({0}); return false;", DataBinder.Eval(e.Row.DataItem, "id"));
            }
        }
        if (e.Row.RowIndex != -1)
        {
            e.Row.Cells[0].Text = (e.Row.RowIndex + (Pager.PageSize * (Pager.CurrentPageIndex - 1) + 1)).ToString();
        }
        
    }

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (Session["sRole"].ToString() == "老师")
        {
            e.Row.Cells[3].Visible = true;
            e.Row.Cells[4].Visible = true;
        }
        else
        {
            e.Row.Cells[3].Visible = false;
            e.Row.Cells[4].Visible = false;
        }
    }

    protected void pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        Pager.CurrentPageIndex = e.NewPageIndex;
        if (ViewState["sqlwhere"] != null)
        {
            DataBrid(ViewState["sqlwhere"].ToString());
        }
        else
        {
            DataBrid();
        }

    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        string strWhere = Session["sqlwhere"].ToString();
        if (!string.IsNullOrEmpty(KeChengMingCheng.Text))
        {
            strWhere += " and name like '%" + KeChengMingCheng.Text + "%'";
        }
        if (!string.IsNullOrEmpty(ShouKeLaoShi.Text))
        {
            strWhere += " and username1 like '%" + ShouKeLaoShi.Text + "%'";
        }
        Pager.CurrentPageIndex = 0;
        ViewState["sqlwhere"] = strWhere;
        DataBrid(ViewState["sqlwhere"].ToString());
    }



  
    protected void LB_Click(object sender, EventArgs e)
    {
        KeChengMingCheng.Text = "";
        ShouKeLaoShi.Text = "";
        LinkButton lb = (LinkButton)sender;
        switch (lb.ID)
        {
            case "LB1":
                DataBrid(" WHERE (([laoshi] = '" + Session["sUserName"].ToString().Trim() +
    "' OR [writer] = '" + Session["sUserName"].ToString().Trim()+"') AND (([confirm] = '新建') OR ([confirm] = '审核未通过') OR ([confirm] = '终审未通过')))");
                ViewState["sqlwhere"] = " WHERE (([laoshi] = '" + Session["sUserName"].ToString().Trim() +
    "' OR [writer] = '" + Session["sUserName"].ToString().Trim() + "') AND (([confirm] = '新建') OR ([confirm] = '审核未通过') OR ([confirm] = '终审未通过')))";
                Session["sqlwhere"] = ViewState["sqlwhere"];
                LB1.Attributes.Add("style", "background:url(../images/study3.gif) left top no-repeat;color:#fff;");
                LB2.Attributes.Add("style", "background:url(../images/study4.gif) left top no-repeat;color:#000;");
                LB4.Attributes.Add("style", "background:url(../images/study4.gif) left top no-repeat;color:#000;");
                break;
            case "LB2":
                DataBrid(" WHERE (([laoshi] = '" + Session["sUserName"].ToString().Trim() +
            "' OR [writer] = '" + Session["sUserName"].ToString().Trim() + "') AND (([confirm] = '提交') OR ([confirm] = '审核通过')))");
                ViewState["sqlwhere"] = " WHERE (([laoshi] = '" + Session["sUserName"].ToString().Trim() +
            "' OR [writer] = '" + Session["sUserName"].ToString().Trim() + "') AND (([confirm] = '提交') OR ([confirm] = '审核通过')))";
                Session["sqlwhere"] = ViewState["sqlwhere"];
                LB1.Attributes.Add("style", "background:url(../images/study4.gif) left top no-repeat;color:#000;");
                LB2.Attributes.Add("style", "background:url(../images/study3.gif) left top no-repeat;color:#fff;");
                LB4.Attributes.Add("style", "background:url(../images/study4.gif) left top no-repeat;color:#000;");
                break;
           
            case "LB4":
                DataBrid(" WHERE (([laoshi] = '" + Session["sUserName"].ToString().Trim() +
            "' OR [writer] = '" + Session["sUserName"].ToString().Trim() + "') AND ([confirm] = '终审通过'))");
                ViewState["sqlwhere"] = " WHERE (([laoshi] = '" + Session["sUserName"].ToString().Trim() +
            "' OR [writer] = '" + Session["sUserName"].ToString().Trim() + "') AND ([confirm] = '终审通过'))";
                Session["sqlwhere"] = ViewState["sqlwhere"];
                LB1.Attributes.Add("style", "background:url(../images/study4.gif) left top no-repeat;color:#000;");
                LB2.Attributes.Add("style", "background:url(../images/study4.gif) left top no-repeat;color:#000;");
                LB4.Attributes.Add("style", "background:url(../images/study3.gif) left top no-repeat;color:#fff;");
                break;
        }

    }
}
